
package ch.ethz.ssh2.crypto.cipher;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;

import android.util.Log;

public class CipherOutputStreamAsync
{
	BlockCipher currentCipher;
	OutputStream bo;
	int blockSize;

	public CipherOutputStreamAsync(BlockCipher bc, OutputStream bo)
	{
		this.bo = bo;
		this.currentCipher = bc;
		blockSize = bc.getBlockSize();
	}

	public void encrypt(byte[] src, int len, byte[] enc) throws IOException
	{
/*
condition:
src.length % blockSize = 0
len == enc.length
*/	
		int offset = 0;
		while (offset < len)
		{
			currentCipher.transformBlock(src, offset, enc, offset);
			offset += blockSize;
		}
	}

	public void write(byte[] src, int off, int len) throws IOException
	{
		bo.write(src, off, len);
		bo.flush();
	}

	public void flush() throws IOException
	{
		bo.flush();
	}

	public void setIV(byte[] iv) {
		currentCipher.setIV(iv);
	}
	
}
